﻿#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    QHotkey hotkey(QKeySequence("ctrl+alt+Q"), true);//The hotkey will be automatically registered
    qDebug() << "Is Registered: " << hotkey.isRegistered();

    QObject::connect(&hotkey, &QHotkey::activated, qApp, [&](){
        qDebug() << "Hotkey Activated - the application will quit now";
        qApp->quit();
    });

     QHotkey hotkey1(QKeySequence("ctrl+Q"), true);
    QObject::connect(&hotkey1, &QHotkey::activated, qApp, [&](){
        qDebug() << "Hotkey Activated - the application will quit now";
         // 假设你有一个QWidget指针叫做 myWidget
         if (w.isHidden()) {
             // 窗口是隐藏的
             qDebug() << "Window is hidden";
             w.show();
         } else {
             // 窗口是显示的
             qDebug() << "Window is show";
             w.hide();
         }
        // w.show();
    });

    return a.exec();
}
